<template>
  <div>
    <approve-common
      v-bind="$attrs"
      :view-mode="isView"
      :related-data="relatedData"
      :approve-data="approveData"
      :before-save="submit"
      @success="handleSuccess"
    >
      <template slot="inner">
        <div v-if="isView" class="text-left px-2 pt-2">评审方式：{{ approveTypeLabel }}</div>
        <div v-else class="d-flex align-items-center p-2 bg-edit">
          <div>评审方式：</div>
          <c-radio-group v-model="formType" number-key :options="enumApproveType"></c-radio-group>
        </div>
      </template>

      <div v-if="!isView" slot="after" class="d-flex">
        <div style="width: 20%"></div>
        <div>
          <el-button type="text" icon="el-icon-edit" @click="handleRiskReport">
            风险审查报告
          </el-button>
        </div>
      </div>
    </approve-common>

    <risk-report :visible.sync="riskVisible" :view-mode="false" :query-id="relatedId"></risk-report>
  </div>
</template>

<script>
import { updateRelatedData } from '@/credit/views/county/unionProvince/components/projectApprove/index'
import ApproveCommon from '@/credit/views/county/unionProvince/components/projectApprove/ApproveCommon'
import RiskReport from '@/credit/views/county/unionProvince/components/riskReport/Dialog'

export default {
  components: {
    ApproveCommon,
    RiskReport,
  },
  props: {
    relatedData: {
      type: Object,
      default: () => ({}),
    },
    approveData: {
      type: Object,
      default: () => ({
        editable: false,
        record: [],
      }),
    },
    viewMode: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      loading: false,

      enumApproveType: [
        { value: 1, label: '线上评审' },
        { value: 2, label: '线下评审' },
      ],
      formType: 2,

      riskVisible: false,
    }
  },
  computed: {
    relatedId() {
      return this.relatedData.customer_related_id
    },
    isView() {
      return this.viewMode || !this.approveData.editable
    },
    approveTypeLabel() {
      const item = this.enumApproveType.find(it => it.value === +this.relatedData.review_method)
      return item ? item.label : ''
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submit() {
      return updateRelatedData(this.relatedId, {
        review_method: this.formType,
      })
    },

    handleSuccess(res) {
      this.$emit('success', res)
    },

    handleRiskReport() {
      this.riskVisible = true
    },
  },
}
</script>

<style lang="scss" scoped></style>
